<template>
  <div>
    <el-row type="flex" justify="center">
      <el-col :span="6">
        <el-form :model="userinfo" label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="userinfo.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="userinfo.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item label>
            <el-button type="primary"  @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {}
    };
  },
  methods:{
      login(){

          this.axios.post("/login",this.userinfo).then(resp=>{
              console.log(resp.data)

              sessionStorage.setItem("username",resp.data.username)
              sessionStorage.setItem("uid",resp.data.uid)

              this.$message({
                  "message":"登录成功",
                  "type":"success"
              })

            //回调到callback
            const callback=this.$route.query.callback
            if(callback){
                this.$router.push({"path":callback})
            }

          }).catch(error=>{
              console.log(error)
          })
      }
  }
};
</script>

<style>
</style>